package cn.wolfcode.edu.web.controller;

import cn.wolfcode.edu.domain.ClassGrade;
import cn.wolfcode.edu.domain.Client;
import cn.wolfcode.edu.domain.FormalStudent;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IFormalStudentService;
import cn.wolfcode.edu.util.JsonResult;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by 徐沅澧 on 2018/7/9.
 */
@Controller
@RequestMapping("formalStudent")
public class FormalStudentController {

    @Autowired
    private IFormalStudentService studentService;

    @RequestMapping("")
    public String index(){
        return "formalstudent";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(QueryObject qo) {
        return studentService.query(qo);
    }

    /*学员信息更新*/
    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(FormalStudent student) {
        JsonResult result = new JsonResult();
        try {
            studentService.update(student);
        } catch (Exception e) {
            e.printStackTrace();
            result = result.remark("编辑学员信息失败!请稍后再试!");
        }
        return result;
    }
    /*学员转班*/
    @RequestMapping("transfer")
    @ResponseBody
    public JsonResult transfer(FormalStudent student) {
        JsonResult result = new JsonResult();
        try {
            studentService.updateForTransfer(student);
        } catch (Exception e) {
            e.printStackTrace();
            result = result.remark("转班操作失败!请稍后再试!");
        }
        return result;
    }

    /*学生退学*/
    @RequestMapping("quitStudent")
    @ResponseBody
    public JsonResult quitStudent(Long id,int statusVal) {
        JsonResult result = new JsonResult();
        try {
            studentService.quitStudent(id,statusVal);
        } catch (Exception e) {
            e.printStackTrace();
            result = result.remark("操作失败!请稍后再试!");
        }
        return result;
    }
    /*查询尚未缴清学费的学生*/
    @RequestMapping("listAllNotYetPay")
    @ResponseBody
    public List<FormalStudent> listAllNotYetPay() {
        return studentService.listAllNotYetPay();

    }
    /*潜在客户转正*/
    @RequestMapping("client2Formal")
    @ResponseBody
    public JsonResult client2Formal(Client client,FormalStudent formalStudent) {
        JsonResult result = new JsonResult();
        try {
            studentService.client2Formal(client,formalStudent);
        } catch (Exception e) {
            e.printStackTrace();
            result = result.remark("操作失败!请稍后再试!");
        }
        return result;
    }

    /*基础班学员升班*/
    @RequestMapping("upgrade")
    @ResponseBody
    public JsonResult upgrade(Long nowClz, Long newClz) {
        JsonResult result = new JsonResult();
        try {
            studentService.upgrade(nowClz,newClz);
        } catch (Exception e) {
            e.printStackTrace();
            result = result.remark("操作失败!请稍后再试!");
        }
        return result;
    }
}